-
Notifications
You must be signed in to change notification settings - Fork 1
test(llm-tool): add complex structured tool test #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Caution Review failedThe pull request is closed. WalkthroughA new test case has been added to validate the integration of the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/llm-tool.spec.ts (4)
107-141
: Good addition of a complex structured tool test caseThis test case effectively validates the integration between the
GameCharacterV2
class and OpenAI's Chat Completions API. It tests the conversion of a complex class structure to an OpenAI tool and verifies that the response properly follows the expected schema.However, I noticed that line 137 duplicates the assertion from line 127 (
expect(data3.location).toBeDefined()
).Remove the duplicate assertion:
expect(data3.status).toBeDefined(); - expect(data3.location).toBeDefined(); expect(data3.titles[0]).toBeDefined();
108-109
: Consider enhancing the user prompt for better test reliabilityThe current user message is quite minimal. For a complex structure like
GameCharacterV2
, providing more specific guidance in the prompt could lead to more consistent test results.Consider expanding the prompt to include more specific guidance about what kind of game character to create:
- const userMessage = `You are a helpful AI assistant. Based on the following JSON schema for a game character, please generate a mock response that follows the schema exactly. Make the data realistic and consistent with a game character context. - `; + const userMessage = `You are a helpful AI assistant. Based on the following JSON schema for a game character, please generate a mock response that follows the schema exactly. Create a character for an RPG game with appropriate levels, stats, location, bank accounts, titles, and status. Make the data realistic and consistent with a game character context.`;
124-126
: Consider adding error handling for tool calls parsingThe current implementation assumes that the tool call will always be successful and present in the response.
Add error handling to make the test more robust:
- const data3: GameCharacterV2 = JSON.parse( - completion.choices[0].message?.tool_calls[0].function.arguments, - ); + expect(completion.choices[0].message?.tool_calls?.length).toBeGreaterThan(0); + const toolCall = completion.choices[0].message?.tool_calls?.[0]; + expect(toolCall).toBeDefined(); + expect(toolCall.function.name).toBe('game_character_v2'); + const data3: GameCharacterV2 = JSON.parse(toolCall.function.arguments);
127-140
: Consider adding stronger schema validationThe current test only checks if properties are defined but doesn't validate their types or structure in depth.
Consider adding more comprehensive validation for at least a few of the properties:
expect(data3.location).toBeDefined(); expect(data3.location.city).toBeDefined(); expect(data3.location.country).toBeDefined(); + expect(typeof data3.location.city).toBe('string'); + expect(typeof data3.location.country).toBe('string'); expect(data3.banks[0].account).toBeDefined(); expect(data3.banks[0].bankName).toBeDefined(); + expect(typeof data3.banks[0].account).toBe('string'); + expect(typeof data3.banks[0].bankName).toBe('string'); expect(data3.level).toBeDefined(); + expect(typeof data3.level).toBe('number'); expect(data3.name).toBeDefined(); expect(data3.rank).toBeDefined(); expect(data3.status).toBeDefined(); expect(data3.titles[0]).toBeDefined(); expect(data3.scores[0]).toBeGreaterThan(0); expect(data3.availableStatuses[0]).toBeDefined(); + expect(Array.isArray(data3.titles)).toBe(true); + expect(Array.isArray(data3.scores)).toBe(true); + expect(Array.isArray(data3.availableStatuses)).toBe(true);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/llm-tool.spec.ts
(2 hunks)
🔇 Additional comments (1)
src/llm-tool.spec.ts (1)
10-10
: Appropriate import added for the new test caseThe import for
GameCharacterV2
is correctly added to support the new test case for complex structured tool testing.
6d6cb89
to
6a58629
Compare
What does this PR do?
xxx
Type of change
This pull request is a
Which introduces
How should this be manually tested?
xxx
What are the requirements to deploy to production?
Any background context you want to provide beyond Shortcut?
xxx
Screenshots (if appropriate)
xxx
Loom Video (if appropriate)
xxx
Any Security implications
xxx
Summary by CodeRabbit
Tests
Documentation
Chores
Changelog